package com.mornd.gulimall.order.feign;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.mornd.gulimall.apis.order.IOrderClient;
import com.mornd.gulimall.apis.order.to.OrderPageTo;
import com.mornd.gulimall.apis.order.to.OrderTo;
import com.mornd.gulimall.common.core.result.R;
import com.mornd.gulimall.order.entity.Order;
import com.mornd.gulimall.order.service.IOrderService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author: mornd
 * @dateTime: 2023/7/23 - 10:38
 */

@RestController
public class OrderClient implements IOrderClient {

    @Resource
    private IOrderService orderService;

    @Override
    public R<OrderTo> getOrderBySn(String orderSn) {
        Order order = orderService.getOne(Wrappers.<Order>lambdaQuery().eq(Order::getOrderSn, orderSn));
        if (order == null) {
            return R.ok();
        }
        OrderTo orderTo = new OrderTo();
        BeanUtils.copyProperties(order, orderTo);
        return R.ok(orderTo);
    }

    @Override
    public R<OrderPageTo> pageOrderWithItemByUser(OrderPageTo orderPageTo) {
        OrderPageTo page = orderService.pageWithItemByUser(orderPageTo);
        return R.ok(page);
    }
}
